#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dominion.h"

int handValue(int hand[], int size){
	int i = 0;
	int total = 0;
	for(i=0; i < size; ++i){
		if(hand[i] == copper){
			total += 1;
		}else if(hand[i] == silver){
			total += 2;
		}else if(hand[i] == gold){
			total += 3;
		}
	}
	return total;
}


void testMine(){
	int k[10] = {adventurer, council_room, feast, gardens, mine,
	       remodel, smithy, village, baron, great_hall};
	
	struct gameState *game = newGame();
	initializeGame(3, k, 10, game);
	struct gameState *test = malloc(sizeof(struct gameState));
	memcpy(test, game, sizeof(struct gameState));
	int p = test->whoseTurn;
	int coin = 0;
	if(cardEffect(mine, council_room, 0, 0, test, 0, &coin) == -1)
		printf("mine: PASS Cannot trash action card\n");
	else
		printf("mine: FAIL trashed action card\n");
	
	test->hand[p][1] = copper;
	if(cardEffect(mine, 1, gold, 0, test, 0, &coin) == -1)
		printf("mine: PASS Can only upgrade by 2\n");
	else
		printf("mine: FAIL Upgraded to far\n");
	
	if(cardEffect(mine, silver, council_room, 0, test, 0, &coin) == -1)
		printf("mine: PASS Cannot upgrade to action card\n");
	else
		printf("mine: FAIL Upgraded to action card\n");
		
	cardEffect(mine, silver, council_room, 0, test, 0, &coin);
	if(handValue(test->hand[p], test->handCount[p]) == handValue(game->hand[p], game->handCount[p])+2)
		printf("mine: PASS Treasure card upgraded\n");
	else
		printf("mine: FAIL Treasure card not updgraded\n");
	if(test->handCount[test->whoseTurn] == game->handCount[test->whoseTurn]-1)
		printf("mine: PASS No cards drawn\n");
	else
		printf("mine: FAIL Cards Drawn\n");
	
	if(test->numBuys == game->numBuys)
		printf("mine: PASS buys not effected\n");
	else
		printf("mine: FAIL buys shouldn't be changed\n");
		
	if(test->numActions == game->numActions)
		printf("mine: PASS No Actions Added\n");
	else
		printf("mine: FAIL No Actions Added\n");	
	
}



int main(int argc, char *argv[]){
    testMine();
    return 0;
}



